import constant from './constant'

// 存储变量名
let storageKey = 'storage_data'

// 存储节点变量名
let storageNodeKeys = Object.keys(constant)


const storage = {
	set: function(key, value) {

		if (storageNodeKeys.indexOf(key) != -1) {
			let tmp = uni.getStorageSync(storageKey)
			tmp = tmp ? tmp : {}
			tmp[key] = value
			uni.setStorageSync(storageKey, tmp)
		} else {
			console.log(key, value);
			uni.setStorageSync(key, value)
		}
	},
	get: function(key) {
		let storageData = uni.getStorageSync(storageKey) || {}
		return storageData[key] || ""
	},
	remove: function(key) {
		let storageData = uni.getStorageSync(storageKey) || {}
		delete storageData[key]
		uni.setStorageSync(storageKey, storageData)
	},
	clean: function() {
		uni.removeStorageSync(storageKey)
	},
	// 获取自己定义的数据
	setItem: function(key, value) {
		uni.setStorageSync(key, value)
	},
	getItem: function(key) {
		let storageData = uni.getStorageSync(key) || null
		return storageData || null
	},
	removeItem: function(key) {
		uni.removeStorageSync(key);
	},

}

export default storage